package com.city.repository.report;

import com.city.domain.report.CtUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface CtUserRepository extends JpaRepository<CtUser,Integer>{

    @Query(value = "SELECT u.id id ,u.name name ,u.password password ,u.grid_index grid_index ," +
            "u.business_index business_index ,u.command_index command_index , u.house_index house_index ," +
            "u.supervise_index supervise_index ,u.special_index special_index,u.auth_index auth_index ," +
            "b.name branch_name ," +
            " c.id branch_id " +
            "from ct_user as u " +
            "left join ct_user_branch as c on c.branch_id = b.id " +
            "LEFT JOIN ct_branch as b on u.branch_id = b.id ",nativeQuery = true)
    List<CtUser> findByPage(Integer page,Integer limit);


    @Query(value = "select * from ct_user where name = ?1 and password =?2",nativeQuery = true)
    CtUser findByNameAndPassword(String name,String password);

    @Query(value = "select * from ct_user where name = ?1",nativeQuery = true)
    CtUser findByName(String name);

    @Query(value = "delete from ct_user where id = ?1",nativeQuery = true)
    void deleteById(Integer id);
}
